﻿namespace WebApplication1
{
    public class CustomRoutingInterceptor
    {
        private readonly RequestDelegate _next;

        public CustomRoutingInterceptor(RequestDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            // 在此处拦截路由
            var path = context.Request.Path.Value.ToLower();

            if (path.StartsWith("/api/private"))
            {
                // 如果请求被拦截，可以返回错误或进行重定向
                context.Response.ContentType = "Content-Type: text/html; charset=utf-8'";
                context.Response.WriteAsync(File.ReadAllText("D:\\Desktop\\新建文本文档 (10).txt",System.Text.Encoding.UTF8));
                return;
            }

            // 如果没有被拦截，则继续请求处理
            await _next(context);
        }
    }
}
